import amapFile from '@/order/amap-wx.js'
import { AMapKey } from '@/common/config'

export const AMap = new amapFile.AMapWX({
  key: AMapKey
})

export const modules = [
  { label: '模板一' },
  { label: '模板二' }
]

export const payWay = [
  { label: '挂账', value: 3 },
  { label: '预付', value: 1 }
]
export const products = [
  { value: 1, name: '出团' },
  { value: 2, name: '一日游' },
  { value: 3, name: '接送' },
  { value: 4, name: '会议' },
  { value: 5, name: '其他' }
]

export const vehicleType = [
  { label: '自有车辆' },
  { label: '外调车辆' }
]

export const driverType = [
  { label: '自有', value: 0 },
  { label: '外调', value: 2 },
  { label: '平台', value: 1 }
]

export const status = [
  { value: 0, label: '待接单' },
  { value: 1, label: '待接单' },
  { value: 2, label: '待车企确认' },
  { value: 3, label: '已取消' },
  { value: 4, label: '待出发' },
  { value: 5, label: '已拒绝' },
  { value: 6, label: '进行中' },
  { value: 7, label: '行程结束' },
  { value: 8, label: '已完成' },
  { value: 9, label: '异议' },
  { value: 10, label: '已取消并退款' },
  { value: 11, label: '待客户确认' }
]

export const hookStatus = [
  { value: 0, label: '待接单' },
  { value: 1, label: '已接单' },
  { value: 2, label: '已取消' },
  { value: 3, label: '已超时' }
]

export const getStatus = (value, hook = false) => {
  let label = ''
  const list = hook ? hookStatus : status
  list.forEach(item => {
    if (item.value === value) label = item.label
  })
  return label
}

/**
 * 逆地址解析（坐标转具体位置信息）
 * @export
 * @param {*} location 坐标：'116.307520,39.984060'(经度，纬度)
 * @returns
 */
export function reverseGeocoder(location) {
  return new Promise((resolve, reject) => {
    AMap.getRegeo({
      location,
      success: (res) => {
        resolve(res[0].regeocodeData)
      },
      fail: (info) => {
        console.log(info)
      }
    })
  })
}

/**
 * 地图关键词搜索
 * @export
 * @param {*} querykeywords 搜索关键词
 * @param {*} location 坐标：'116.307520,39.984060'(经度，纬度)
 * @returns
 */
export function mapSearch(querykeywords, location) {
  return new Promise((resolve, reject) => {
    AMap.getPoiAround({
      querykeywords,
      location,
      success: (res) => {
        resolve(res.poisData)
      },
      fail: (info) => {
        console.log(info)
      }
    })
  })
}
